package cn.zf233.xcloud.intercept;

import cn.zf233.xcloud.exception.MaintainException;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Calendar;

/**
 * Created by zf233 on 2021/2/28
 * 维护时间段拦截器
 */
public class MaintainIntercept implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        Calendar calendar = Calendar.getInstance();
        int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
        if (currentHour == 1) {
            throw new MaintainException("XCloud 正在维护（维护时间 1:00 - 2:00）");
        }
        return true;
    }
}
